package com.example.amone.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.amone.R;
import com.example.amone.bean.GroupBean;

import java.util.List;

public class GroupAdapter extends RecyclerView.Adapter<GroupAdapter.GroupViewHolder> {

    private static final String TAG = GroupAdapter.class.getSimpleName();
    private List<GroupBean> groupBeanList;
    private Context context;

    public GroupAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public GroupViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_group, viewGroup, false);
        return new GroupViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull GroupViewHolder groupViewHolder, int i) {
        if (groupViewHolder instanceof GroupViewHolder) {
            groupViewHolder.ll_group.setBackgroundResource(R.mipmap.ic_launcher);
            groupViewHolder.tvGroup.setText(groupBeanList.get(i).getGroupName());
        }
    }

    @Override
    public int getItemCount() {
        return groupBeanList == null ? 0 : groupBeanList.size();
    }

    public void setGroupList(List<GroupBean> groupBeanList) {
        this.groupBeanList = groupBeanList;
        Log.d(TAG, groupBeanList + "");
        notifyDataSetChanged();
    }

    class GroupViewHolder extends RecyclerView.ViewHolder {

        LinearLayout ll_group;
        TextView tvGroup;

        public GroupViewHolder(@NonNull View itemView) {
            super(itemView);
            ll_group = itemView.findViewById(R.id.ll_group);
            tvGroup = itemView.findViewById(R.id.tv_group);
        }
    }
}
